package com.atguigu.tingshu.album.api;

import cn.hutool.json.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value = "/api/album")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {

    @Autowired
    private BaseCategoryService baseCategoryService;

    @Operation(summary = "查看专辑分类")
    @GetMapping("/category/getBaseCategoryList")
    public Result<List<JSONObject>> getCategoryList() {
        List<JSONObject> list = baseCategoryService.getCategoryList();
        return Result.ok(list);
    }

    @Operation(summary = "专辑标签列表")
    @GetMapping("/category/findAttribute/{category1Id}")
    public Result<List<BaseAttribute>> getAttributesById(@PathVariable("category1Id") Long category1Id) {
        List<BaseAttribute> attributeList = baseCategoryService.getAttributesById(category1Id);
        return Result.ok(attributeList);
    }

    @Operation(summary = "根据三级分类id获取专辑分类信息")
    @GetMapping("/category/getCategoryView/{category3Id}")
    public Result<BaseCategoryView> getCategoryView(@PathVariable Long category3Id) {
        BaseCategoryView baseCategoryView = baseCategoryService.getCategoryView(category3Id);
        return Result.ok(baseCategoryView);
    }

    /**
     * 根据一级分类ID查询三级分类TOP7集合
     *
     * @param category1Id 级分类ID
     * @return List<JSONObject> 三级分类TOP7集合
     */
    @Operation(summary = "根据一级分类ID查询三级分类top7列表")
    @GetMapping("/category/findTopBaseCategory3/{category1Id}")
    public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable Long category1Id) {
        List<BaseCategory3> category3Top7List = baseCategoryService.findTopBaseCategory3(category1Id);
        return Result.ok(category3Top7List);
    }

    /**
     * 获取一级分类全部分类信息
     *
     * @param category1Id 一级分类ID
     * @return JSONObject
     */
    @Operation(summary = "获取一级分类全部分类信息")
    @GetMapping("/category/getBaseCategoryList/{category1Id}")
    public Result<JSONObject> getBaseCategoryList(@PathVariable Long category1Id) {
        JSONObject jsonObject = baseCategoryService.getBaseCategoryList(category1Id);
        return Result.ok(jsonObject);
    }

    /**
     * 查询所有一级分类列表
     *
     */
    @Operation(summary = "查询所有一级分类列表")
    @GetMapping("/category/findAllCategory1")
    public Result<List<BaseCategory1>> findAllCategory1() {
      List<BaseCategory1> category1List =  baseCategoryService.findAllCategory1();
        return Result.ok(category1List);
    }
}

